﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 虚线
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


        }
        Bitmap bitmap;
        private void Form1_Load(object sender, EventArgs e)
        {
            
            bitmap = new Bitmap(500, 500);

            for (int i = 0; i < bitmap.Width; ++i)
            {
                for (int j = 0; j < bitmap.Height; ++j)
                {
                    bitmap.SetPixel(i, j, Color.FromArgb(255, 255, 255));
                }
            }
            pictureBox1.Image = bitmap;
        }

        void MidpointLine1(int x0,int y0,int x1,int y1,Color color)
        {
            int a, b, delta1, delta2, d, x, y;
            a = y0 - y1;
            b = x1 - x0;
            d = 2 * a + b;
            delta1 = 2 * a;
            delta2 = 2 * (a + b);
            x = x0;
            y = y0;
            bitmap.SetPixel(x, y, color);
            while(x<x1)
            {
                if(d<0)
                {
                    ++x;
                    ++y;
                    d += delta2;
                }
                else
                {
                    ++x;
                    d += delta1;
                }
                if((x-x0)%20<=10)
                {
                    bitmap.SetPixel(x, y, color);
                }
                
            }
            

        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            MidpointLine1(10,10,440,440, Color.FromArgb(0, 0, 0));
            pictureBox1.Image = bitmap;
        }



 
    }
}
